<!DOCTYPE html>
<html>
<head>
    <title>随笔</title>
    <#include "header.html">

    <style>
        html body {
            background-color: #F6F7F9;
        }

        #app {
            margin-top: 0px;
            margin-left: 0px;
            margin-right: 0px;
        }
        .but{
            bottom: 20px;
            position: fixed;
            z-index: 1;
            width: 96%;
        }
        .divten{
            width: 96%;
            margin: 0 auto;
        }
        .mint-header {
            background: #fff;
            color: #24253D;
            margin-bottom: 10px;
        }
    </style>
</head>
<body>

<div id="app"  style=" height: 100%;" v-cloak>

    <mt-header  title="忘记密码">
        <router-link to="/" slot="left">
            <mt-button @click.native="javaScript:history.go(-1)" icon="back">返回</mt-button>
        </router-link>
    </mt-header>

    <div>
        <div class="divten">
            <mt-field label="手机号" placeholder="请输入手机号" type="phone" v-model.trim="phone"></mt-field>
            <mt-field label="新密码" placeholder="请输入新密码" type="password" v-model.trim="newPassword"></mt-field>
            <mt-button type="primary" class="but" @click.native="updatePsw()">确认</mt-button>
        </div>
    </div>
    <div style="height: 60px;"></div>
</div>

<input type="hidden" value="${openId}" id="openId">
</body>

<script>

    var vm = new Vue({
        el: '#app',
        data: {
            useUserInfo: {},
            openId: $("#openId").val(),
            phone:"",
            newPassword:""
        },
        created: function () {
            this.selected = '首页';
        },
        methods: {
            updatePsw: function () {
                if (!vm.phone) {
                    this.$toast("请输入手机号");
                    return;
                }
                if (!vm.newPassword) {
                    this.$toast("请输入新密码");
                    return;
                }
                $.ajax({
                    type: "POST",
                    url:   "../../wx/student/updatePsw",
                    timeout:30000,
                    contentType: "application/x-www-form-urlencoded",
                    data: {
                        openId : vm.openId,
                        phone : vm.phone,
                        newPassword : vm.newPassword
                    },
                    beforeSend:function (){
                        vm.$indicator.open();
                    },
                    success: function(r){
                        if(r.code === 0){
                            vm.$indicator.close();
                            vm.$toast({
                                message: r.msg,
                                iconClass: 'icon icon-success'
                            });

                        }else{
                            vm.$indicator.close();
                            vm.$toast({
                                message: '操作失败',
                                duration: 2000
                            });
                        }
                        vm.$indicator.close();

                    },
                    error :function () {
                        vm.$indicator.close();
                        vm.$toast({
                            message: '操作失败',
                            duration: 2000
                        });
                    }
                });
            },
            /*goback: function () {
                window.location.href = "../../wx/student/center?openId=" + document.getElementById("openId").value + "&userId=" + document.getElementById("userId").value;
            },*/
        }
    })

</script>
</html>